import { ADDRESS_LIST_DATA,SHOW_CHICE_ADDRESS} from "./actionsTypes";
export const addressList = data => ({type: ADDRESS_LIST_DATA, data: data});//地址列表
export const showChiceAddress = data => ({type: SHOW_CHICE_ADDRESS, data: data});//地址列表

import getAddAddressListService from  '../services/addAddressListService';
import {Toast} from 'antd-mobile'

export const getAddAddressList=(data,callBack)=>{
	 return (dispatch, getState)=>{
		Toast.hide();
		Toast.loading("", 30, () => Toast.info("网络错误", 2));
		getAddAddressListService.addressLista(data).then(resultData => {
			Toast.hide();
			if(resultData.code==1000){
				callBack(resultData.body.addressMsgList)
				// dispatch(addressList(resultData.body.addressMsgList));
			}else {
				Toast.info(resultData.msg,1)
			}
		})
	 }
}

export const setDefaultAddress=(data,callBack)=>{
	return (dispatch, getState)=>{
		Toast.hide();
		Toast.loading("", 30, () => Toast.info("网络错误", 2));
		getAddAddressListService.setDefaultAddress(data).then(resultData => {
			Toast.hide();
			if(resultData.code==1000){
				callBack(resultData.body.addressMsgList);
			}else {
				Toast.info(resultData.msg,1)
			}
		})
	}
}
